<template>
  <div class="page photoclip">
    <div class="clip">
      <div id="clipArea"></div>
      <input
        type="file"
        id="file"
      >
      <button id="clipBtn">截取</button>
      <div id="view"></div>
    </div>
    <van-button
      class="default"
      @click="backHome"
      type="primary"
    >返回首页</van-button>
  </div>
</template>

<script>
import PhotoClip from 'photoclip'

export default {
  name: 'photoclip',
  data () {
    return {
    }
  },
  mounted () {
    let pc = new PhotoClip('#clipArea', {
      size: [260, 260],
      outputSize: 640,
      file: '#file',
      view: '#view',
      ok: '#clipBtn',
      loadStart: () => {
        console.log('开始读取照片');
      },
      loadComplete: () => {
        console.log('照片读取完成');
      },
      done: (dataURL) => {
        console.log(dataURL);
      },
      fail: (msg) => {
        this.$toast(msg);
      }
    });
  },
  created () {
  },
  computed: {
  },
  methods: {
    backHome () {
      this.$router.replace({ name: 'home' });
    }
  },
  components: {
  }
}
</script>

<style lang="less" scoped>
.clip {
  position: relative;
  width: 100%;
}
#clipArea {
  margin: 0 auto;
  width: 7rem;
  height: 300px;
}
#file,
#clipBtn {
  margin: 0.2rem auto;
  display: block;
  font-size: 0.24rem;
}
#view {
  margin: 0 auto;
  width: 2rem;
  height: 2rem;
  background-color: #666;
}
.default {
  position: absolute;
  bottom: 5%;
  left: 50%;
  transform: translate(-50%, -50%);
}
</style>

